<?php

class Obj_DBTable_SpecialOffer extends Zend_Db_Table_Abstract
{
    protected $_name = 'special_offer';
    protected $_primary = 'ID';
    
    
    public function getPaginatedSpecialOffers($page, $active_only = false) {
    	$select = $this->select()->from($this)->order("date desc");
    	if($active_only) $select = $select->where("active = 1");
    	$arResult = Zend_Paginator::factory($this->fetchAll($select));
    	$arResult->setItemCountPerPage(BACKEND_ITEMS_PER_PAGE);
    	$arResult->setCurrentPageNumber($page);
    	return $arResult;
    }
    
    public function getAllSpecialOffers($active_only = false) {
    	$select = $this->select()->from($this)->order('ID');
    	if($active_only) $select->where('active=1');
    	return $this->fetchAll($select)->toArray();
    }
      
    public function getSitemapOffers() {
    	$select = $this->select()->from($this, array('ID', 'date'))->order('date desc')->where('active = 1');
    	return $this->fetchAll($select)->toArray();
    }
      
    public function getSpecialOffer($id, $activeOnly = false) {
    	$select = $this->select()->from($this)->where('ID = ?', (int) $id);
    	if ($activeOnly === true) $select->where('active = 1');
    	$res = $this->fetchRow($select);
    	if ($res) {
    		return $res->toArray();
    	}
    	return false;
    }
        
    public function delete($where)
    {
        return $this->_db->delete($this->_name, $where);
    }    
}